#include "checkmouse.h"
#include <QDebug>
#include "configargs.h"
#include <QFile>
#include <QWSServer>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <sys/socket.h>
#include <linux/netlink.h>
#include <sys/types.h>
#include <unistd.h>


#define UEVENT_BUFFER_SIZE 2048
//ceshichumo=0;
CheckThread::CheckThread(QObject *parent) :
    QThread(parent),
    stopped(false)
{
    DebugOrRelease=0;
   
    timercheck = new QTimer;
    connect(timercheck,      SIGNAL(timeout()),     this,   SLOT(timecheckmouxe()));
}

void CheckThread::timecheckmouxe()
{
        system("rm /tmp/checkmouse");
        system("cat  /proc/bus/input/devices > /tmp/checkmouse");
        QFile filecmd("/tmp/checkmouse");
        filecmd.open(QIODevice::ReadWrite);
        QString nametmp(filecmd.readAll());
        QString havekeyboard="Mouse";
        QString havekeyboard1="mouse";
        QString havekeyboard2="MOUSE";

//		qDebug()<<nametmp;

        
        if( nametmp.contains(havekeyboard) || nametmp.contains(havekeyboard1) || nametmp.contains(havekeyboard2)){
            if (!DebugOrRelease){
            	DebugOrRelease = 1;
          		QWSServer::setCursorVisible(true);
 //     			qDebug("mouse is ok");
      			QApplication::setOverrideCursor(Qt::ArrowCursor);
        	}
        }
        else{
            if (DebugOrRelease)
            {
           		DebugOrRelease = 0;
//     			qDebug("mouse is offline");
     			QApplication::setOverrideCursor(Qt::BlankCursor); 
     			QWSServer::setCursorVisible(false);
     		}
        }

}
void CheckThread::run()
{
    timercheck->stop();
    timercheck->start(3000);
}
